package com.payment.system.util;

import com.alibaba.fastjson.JSONObject;
import com.payment.common.utils.SignUtil;
import com.payment.common.utils.StringUtils;
import com.payment.common.utils.http.HttpClientUtil;
import com.payment.common.utils.pay.EncryptUtil;
import com.payment.system.config.GuangGuConfig;
import com.payment.system.domain.Merchant;
import com.payment.system.domain.MerchantIncreaseLimit;
import com.payment.system.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.util.Map;
import java.util.TreeMap;

public class GuangGuUtil {
    private static final Logger log = LoggerFactory.getLogger(GuangGuUtil.class);

    /**
     * 通用接口请求
     *
     * @param params
     * @return
     * @throws Exception
     */
    public static JSONObject request(TreeMap<String, Object> params, String action, String actionCn)
            throws Exception {
        params.put("mch_no", GuangGuConfig.upperNumbers);
        params.put("action", action);
        params.put("sign_type", "MD5");
        // 存在银行卡加密
        if (params.containsKey("bank_card_no")) {
            String bankAccountNo = EncryptUtil.desEncrypt(params.get("bank_card_no").toString(), GuangGuConfig.keys);
            params.put("bank_card_no", bankAccountNo);
        }
        // 存在手机号码加密
        if (params.containsKey("user_phone")) {
            String mobileNo = EncryptUtil.desEncrypt(params.get("user_phone").toString(), GuangGuConfig.keys);
            params.put("user_phone", mobileNo);
        }
        // 存在出款卡号加密
        if (params.containsKey("to_bank_card_no")) {
            String mobileNo = EncryptUtil.desEncrypt(params.get("to_bank_card_no").toString(), GuangGuConfig.keys);
            params.put("to_bank_card_no", mobileNo);
        }
        // 存在预留手机号码加密
        if (params.containsKey("bank_card_phone")) {
            String mobileNo = EncryptUtil.desEncrypt(params.get("bank_card_phone").toString(), GuangGuConfig.keys);
            params.put("bank_card_phone", mobileNo);
        }
        // 存在身份证号加密
        if (params.containsKey("user_id_card")) {
            String idCardNo = EncryptUtil.desEncrypt(params.get("user_id_card").toString(), GuangGuConfig.keys);
            params.put("user_id_card", idCardNo);
        }
        // 存在cnv码加密
        if (params.containsKey("cvn")) {
            String cnv = params.get("cvn").toString();
            if (StringUtils.isEmpty(cnv)) {
                params.put("cvn", cnv);
            } else {
                String bankCvn2 = EncryptUtil.desEncrypt(cnv, GuangGuConfig.keys);
                params.put("cvn", bankCvn2);
            }
        }
        // 存在有效期加密
        if (params.containsKey("valid_date")) {
            String validDatel = params.get("valid_date").toString();

            if (StringUtils.isEmpty(validDatel)) {
                params.put("valid_date", validDatel);
            } else {
                String expired = EncryptUtil.desEncrypt(validDatel, GuangGuConfig.keys);
                params.put("valid_date", expired);
            }

        }
        params.put("sign", SignUtil.sign(params, GuangGuConfig.keys));
        log.info("光谷【" + actionCn + "】上送:" + JSONObject.toJSONString(params));
        String strJson = HttpClientUtil.doPostJson(GuangGuConfig.baseUrls, JSONObject.toJSONString(params));
        if (StringUtils.isEmpty(strJson)) {
            return null;
        }
        JSONObject json = JSONObject.parseObject(strJson);
        log.info("光谷【" + actionCn + "】同步返回:" + json.toJSONString());
        return json;
    }

    /**
     * 用户签约
     *
     * @param mer
     * @return
     * @throws Exception
     */
    public static JSONObject userSign(Merchant mer) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        //请求流水号
        params.put("seria_no", mer.getSeriaNo());
        //注册手机号
        params.put("user_phone", mer.getPhone());
        //姓名
        params.put("user_name", mer.getMerchantCnName());
        //英文名称
        params.put("user_en_name", mer.getMerchantCnName());
        //用户简称
        params.put("user_abb_name", mer.getMerchantCnName());
        //证件类型 1 身份证
        params.put("cre_type", "1");
        //证件号
        params.put("user_id_card", mer.getIdCardNumber());
        //账户类型 1对公 2对私
        params.put("bank_card_type", "2");
        //银行卡号
        params.put("bank_card_no", mer.getBankAccount());
        //预留的手机号
        params.put("bank_card_phone", mer.getReservePhone());
        //银行名称
        params.put("bank_name", mer.getBankName());
        //支行名称
        params.put("bank_sub_name", mer.getBankName());
        //银行代码
        params.put("bank_code", mer.getBankCode());
        //银行代号
        params.put("bank_abbr", mer.getBankAbbr());
        //银行联行号
        params.put("bank_channel_no", mer.getBankDot());
        //签约回调地址
        params.put("mch_notify_url", GuangGuConfig.MCHNOTIFYURL);
        //银行所属省
        params.put("bank_province", mer.getBankProvince());
        //银行所属市
        params.put("bank_city", mer.getBankCity());

        return request(params, "user_sign", "用户签约");
    }

    /**
     * 结算卡变更
     *
     * @return
     * @throws Exception
     */
    public static JSONObject settlementCardModify(SettlementCardModifyVo cardModifyVo) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        params.put("user_id", cardModifyVo.getUserId());
        params.put("user_name", cardModifyVo.getUserName());
        params.put("user_id_card", cardModifyVo.getUserdIdCard());
        params.put("bank_card_no", cardModifyVo.getBankCardNo());
        params.put("bank_name", cardModifyVo.getBankName());
        params.put("bank_code", cardModifyVo.getBankCode());
        params.put("bank_abbr", cardModifyVo.getBankAbbr());
        params.put("bank_channel_no", cardModifyVo.getBankChannelNo());
        params.put("bank_province", cardModifyVo.getBankProvince());
        params.put("bank_city", cardModifyVo.getBankCity());
        params.put("bank_card_phone", cardModifyVo.getBankCardPhone());

        return request(params, "settlement_card_modify", "结算卡变更");
    }

    /**
     * 四要素验证
     *
     * @throws Exception
     */
    public static JSONObject VerificationOfFourElements(Merchant mer) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        //流水号
        params.put("seria_no", mer.getSeriaNo());
        //银行卡号
        params.put("bank_card_no", mer.getBankAccount());
        //姓名
        params.put("name", mer.getMerchantCnName());
        //证件号
        params.put("user_id_card", mer.getIdCardNumber());
        //预留的手机号
        params.put("bank_card_phone", mer.getReservePhone());
        return request(params, "bank_card_auth", "四要素验证");
    }

    /**
     * 通道查询
     *
     * @throws Exception
     */
    public static JSONObject channelQuery() throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        return request(params, "channel_query", "通道查询");
    }


    /**
     * 银行卡签约(信用卡)
     *
     * @throws Exception
     */
    public static JSONObject signingCard(MerchantIncreaseLimit mer) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        //流水号
        params.put("seria_no", mer.getSeriaNo());
        //公司编号
        params.put("company_id", mer.getCompanyId());
        //用户编号
        params.put("user_id", mer.getUserId());
        //账户名称
        params.put("user_name", mer.getBankAccountName());
        //卡号
        params.put("bank_card_no", mer.getBankAccount());
        //证件号
        params.put("user_id_card", mer.getIdCardNumber());
        //预留的手机号
        params.put("bank_card_phone", mer.getBankPhone());
        //信用卡背后三位
        params.put("cvn", mer.getCvn());
        //有效期
        params.put("valid_date", mer.getExpdate());
        //短信验证吗
        params.put("sms_code", mer.getSmsCode());
        //银行代码
        params.put("bank_code", mer.getBankCode());
        //调用段ip地址
        params.put("trx_source_ip", mer.getTrxSourceIp());
        return request(params, "bank_card_sign", "银行卡签约");
    }

    /**
     * 银行卡签约状态查询(信用卡)
     *
     * @throws Exception
     */
    public static JSONObject bankCardSignQuery(MerchantIncreaseLimit mer) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        //流水号
        params.put("seria_no", mer.getSeriaNo());
        //公司编号
        params.put("company_id", mer.getCompanyId());
        //用户编号
        params.put("user_id", mer.getUserId());
        //卡号
        params.put("bank_card_no", mer.getBankAccount());
        //调用段ip地址
        params.put("trx_source_ip", mer.getTrxSourceIp());
        return request(params, "bank_card_sign_query", "银行卡签约状态查询");
    }

    /**
     * 银行卡签约发送短信(信用卡)
     *
     * @throws Exception
     */
    public static JSONObject bankCardSignSendSms(MerchantIncreaseLimit mer, Integer bindType) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        //流水号
        params.put("seria_no", mer.getSeriaNo());
        //公司编号
        params.put("company_id", mer.getCompanyId());
        //用户编号
        params.put("user_id", mer.getUserId());
        //姓名/银行卡账户名
        params.put("user_name", mer.getBankAccountName());
        //卡号
        params.put("bank_card_no", mer.getBankAccount());
        //身份证号
        params.put("user_id_card", mer.getIdCardNumber());
        //预留的手机号
        params.put("bank_card_phone", mer.getBankPhone());
        //银行代码
        params.put("bank_code", mer.getBankCode());
        //卡类型 1、借记卡 2、贷记卡
        params.put("card_type", "2");
        //cvn
        params.put("cvn", mer.getCvn());
        //有效期
        params.put("valid_date", mer.getExpdate());
        params.put("bind_type", bindType.toString());
        // 调用端IP地址
        params.put("trx_source_ip", mer.getTrxSourceIp());
        return request(params, "bank_card_sign_send_sms", "银行卡签约发送短信");
    }

    /**
     * 消费
     *
     * @throws Exception
     */
    public static JSONObject payment(PaymentOrderVO order) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        // 公司编号
        params.put("company_id", order.getAcqCode());
        // 用户编号
        params.put("user_id", order.getUserId());
        // 0无卡 1养卡2空卡3手续费4H5快捷无卡
        params.put("payment_type", order.getPaymentType().toString());
        // 订单id
        params.put("seria_no", order.getOrderNo());
        // 异步通知地址
        params.put("notify_url", GuangGuConfig.PAYMENTURL);
        // 金钱(元)
        params.put("order_amount", order.getAmountMoney().toString());
        // 附加信息摘要
        params.put("memo", "代扣，消费");
        // 费率
        params.put("rate", order.getRate());
        // 笔数费
        params.put("pro", order.getPro().toString());
        // 银行卡号
        params.put("bank_card_no", order.getCreditNumber());
        // 证件号
        params.put("user_id_card", order.getIdCardNo());
        // 预留的手机号
        params.put("bank_card_phone", order.getMobile());
        // 信用卡后三位
        params.put("cvn", order.getMccCode());
        // 有效期
        params.put("valid_date", order.getExpired());
        // 姓名/银行卡户名
        params.put("bank_account_name", order.getBankAccountName());
        // 交易地区
        params.put("region", order.getRegion());
        // 交易客户端ip
        params.put("trx_source_ip", order.getTrxSourceIp());
        // 银行代码
        params.put("bank_code", order.getBankCode());
        // 卡类型 1借记卡 2贷记卡
        params.put("card_type", order.getCardType());
        // 订单号拼接
        params.put("payment_order_ids", order.getOrderNos());
        if (order.getPaymentType().equals(4)) {
            params.put("to_bank_card_no", order.getToBankCardNo());
            params.put("to_bank_channel_no", order.getToBankChannelNo());
            params.put("to_bank_name", order.getToBankName());
            params.put("to_bank_code", order.getToBankCode());
        }
        return request(params, "payment", "消费");
    }


    /**
     * 消费查询
     *
     * @throws Exception
     */
    public static JSONObject merchantConsumeQuery(PaymentOrderVO order) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        //用户编号
        params.put("user_id", order.getUserId());
        //订单号
        params.put("seria_no", order.getOrderNo());

        return request(params, "merchant_consume_query", "消费查询");
    }

    /**
     * 代付，还款
     *
     * @throws Exception
     */
    public static JSONObject repayment(PaymentOrderVO order) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        //公司编号
        params.put("company_id", order.getAcqCode());
        //订单流水号
        params.put("seria_no", order.getOrderNo());
        //0无卡 1养卡
        params.put("payment_type", order.getPaymentType().toString());
        //用户编号
        params.put("user_id", order.getUserId());
        //账户名称
        params.put("user_name", order.getBankAccountName());
        //银行卡号
        params.put("bank_card_no", order.getCreditNumber());
        //账户类型 1个人2企业
        params.put("bank_type", order.getBankType());
        //卡类型 1借记卡 2贷记卡
        params.put("card_type", order.getCardType());
        //银行代码
        params.put("bank_code", order.getBankCode());
        //银行名称
        params.put("bank_name", order.getBankName());
        //证件号
        params.put("user_id_card", order.getIdCardNo());
        //证件类型 1身份证
        params.put("cre_type", "1");
        //预留手机号
        params.put("bank_card_phone", order.getMobile());
        if (order.getMccCode() != null) {
            //信用卡cvn
            params.put("cvn", order.getMccCode());
        }

        if (order.getExpired() != null) {
            //有效期
            params.put("valid_date", order.getExpired());
        }
        //调用端ip
        params.put("trx_source_ip", order.getTrxSourceIp());
        //异步回调
        params.put("notify_url", GuangGuConfig.REPAYMENTURL);
        //金额(元)
        params.put("trade_amount", order.getAmountMoney().toString());
        //费率
        params.put("rate", order.getRate());
        //手续费
        params.put("fee", order.getPro().toString());
        //附加信息摘要
        params.put("memo", "代付，出款");

        params.put("payment_order_ids", order.getOrderNos());
        return request(params, "repayment", "代付，还款");
    }

    /**
     * 代付/还款查询
     *
     * @throws Exception
     */
    public static JSONObject withdrawQuery(PaymentOrderVO order) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        //用户编号
        params.put("user_id", order.getUserId());
        //订单号
        params.put("seria_no", order.getOrderNo());
        return request(params, "repayment_query", "代付/还款查询");
    }

    /**
     * 商户垫资代付 >>> 用户提现
     *
     * @throws Exception
     */
    public static JSONObject repaymentMch(PaymentOrderVO order) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        //公司编号
        params.put("company_id", order.getAcqCode());
        //订单流水号
        params.put("seria_no", order.getOrderNo());
        //用户编号
        params.put("user_id", order.getUserId());
        //姓名
        params.put("user_name", order.getBankAccountName());
        //账户类型 1 个人 2 企业
        params.put("bank_type", order.getBankType());
        //信用卡号
        params.put("bank_card_no", order.getCreditNumber());
        //卡类型 1、借记卡 2、贷记卡
        params.put("card_type", order.getCardType());
        //银行代码
        params.put("bank_code", order.getBankCode());
        //银行名称
        params.put("bank_name", order.getBankName());
        //证件类型1身份证
        params.put("cre_type", "1");
        //证件号码
        params.put("user_id_card", order.getIdCardNo());
        //预留的手机号
        params.put("bank_card_phone", order.getMobile());
        //信用卡cvn
        params.put("cvn", order.getMccCode());
        //有效期
        params.put("valid_date", order.getExpired());
        //调用端ip
        params.put("trx_source_ip", order.getTrxSourceIp());
        //回调地址
        params.put("notify_url", GuangGuConfig.MCHREPAYMENTURL);
        //金钱(元)
        params.put("trade_amount", order.getAmountMoney().toString());
        //费率
        params.put("rate", order.getRate());
        //笔数费
        params.put("fee", order.getPro().toString());
        //附加信息摘要
        params.put("memo", "用户提现");
        return request(params, "repayment_mch", "商户垫资代付 >>> 用户提现");
    }

    /**
     * 垫付代付订单查询
     *
     * @throws Exception
     */
    public static JSONObject mchRepaymentQuery(PaymentOrderVO order) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        //订单号
        params.put("order_no", order.getOrderNo());
        //公司编号
        params.put("company_id", order.getAcqCode());
        return request(params, "mch_repayment_query", "垫付代付订单查询");
    }

    /**
     * 发送短信
     *
     * @throws Exception
     */
    public static JSONObject smsPackage(Map<String, String> map) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        //手机号
        params.put("bank_card_phone", map.get("user_phone"));
        //发送内容
        params.put("content", map.get("content"));
        //有效期(分钟)
        params.put("validity", map.get("validity"));
        //业务类型 SEND_OUT:发送验证 NOTICE:短信通知
        params.put("sendType", map.get("sendType"));
        return request(params, "sms_package", "发送短信");
    }


    /**
     * 钱包查询
     *
     * @throws Exception
     */
    public static JSONObject walletQuery(Merchant mer) throws Exception {
        TreeMap<String, Object> params = new TreeMap<>();
        //用户id
        params.put("user_id", mer.getAcqMerchantNo());
        return request(params, "wallet_query", "商户钱包查询");
    }


    /**
     * 境外消费 获取商品信息
     */
    public static JSONObject getAbroadGoods() throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        JSONObject jsonObject = GuangGuUtil.request(params, "abroad_goods", "境外消费 获取商品信息");
        return jsonObject;
    }

    /**
     * 境外消费 获取获取汇率
     */
    public static JSONObject getAbroadExchangeRate() throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        JSONObject jsonObject = GuangGuUtil.request(params, "abroad_exchange_rate", "境外消费 获取获取汇率");
        return jsonObject;
    }

    /**
     * 境外消费 预下单
     */
    public static JSONObject abroadOrderPay(AbroadOrderVo abroadOrderVo) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("seria_no", abroadOrderVo.getSeriaNo());
        params.put("company_id", abroadOrderVo.getCompanyId());
        params.put("user_id", abroadOrderVo.getUserId());
        params.put("rate", abroadOrderVo.getRate().setScale(2, BigDecimal.ROUND_DOWN).toString());
        params.put("bank_card_no", abroadOrderVo.getBankCardNo());
        params.put("user_name", abroadOrderVo.getUserName());
        params.put("currercy_code", abroadOrderVo.getCurrercyCode());
        params.put("order_amount", abroadOrderVo.getOrderAmount().toString());
        params.put("number", abroadOrderVo.getNumber().toString());
        params.put("exchange_rate", abroadOrderVo.getExchangeRate().setScale(6, BigDecimal.ROUND_DOWN).toString());
        params.put("foreign_amt", abroadOrderVo.getForeignAmt().toString());
        params.put("goods_no", abroadOrderVo.getGoodsNo());
        params.put("front_url", GuangGuConfig.FRONT_URL);
        params.put("notify_url", GuangGuConfig.NOTIFY_URL);
        JSONObject jsonObject = GuangGuUtil.request(params, "abroad_order_pay", "境外消费 预下单");
        return jsonObject;
    }

    /**
     * 境外消费订单查询
     */
    public static JSONObject abroadOrderPayQuery(String seriaNo, String companyId) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("seria_no", seriaNo);
        params.put("company_id", companyId);
        JSONObject jsonObject = GuangGuUtil.request(params, "abroad_order_pay_query", "境外消费订单查询");
        return jsonObject;
    }

    /**
     * 卡测评短信授权获取验证码
     */
    public static JSONObject cardEvaluateSendSms(CardEvaluateSendSmsVo cardEvaluateSendSmsVo) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("bank_card_no", cardEvaluateSendSmsVo.getBankCardNo());
        params.put("name", cardEvaluateSendSmsVo.getName());
        params.put("user_id_card", cardEvaluateSendSmsVo.getUserIdCard());
        params.put("bank_card_phone", cardEvaluateSendSmsVo.getBankCardPhone());
        params.put("seria_no", cardEvaluateSendSmsVo.getSeriaNo());
        JSONObject jsonObject = GuangGuUtil.request(params, "card_evaluate_send_sms", "卡测评短信授权获取验证码");
        return jsonObject;
    }

    /**
     * 卡测评验证短信授权
     */
    public static JSONObject cardEvaluateSendSmsConfirm(CardEvaluateSendSmsVo cardEvaluateSendSmsVo) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("serial_number", cardEvaluateSendSmsVo.getSerialNumber());
        params.put("identifying_code", cardEvaluateSendSmsVo.getIdentifyingCode());
        params.put("seria_no", cardEvaluateSendSmsVo.getSeriaNo());
        JSONObject jsonObject = GuangGuUtil.request(params, "card_evaluate_send_sms_confirm", "卡测评验证短信授权");
        return jsonObject;
    }

    /**
     * 获取卡测评连接地址
     */
    public static JSONObject getCardEvaluateUrl(CardEvaluateSendSmsVo cardEvaluateSendSmsVo) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("bank_card_no", cardEvaluateSendSmsVo.getBankCardNo());
        params.put("name", cardEvaluateSendSmsVo.getName());
        params.put("user_id_card", cardEvaluateSendSmsVo.getUserIdCard());
        params.put("bank_card_phone", cardEvaluateSendSmsVo.getBankCardPhone());
        params.put("seria_no", cardEvaluateSendSmsVo.getSeriaNo());
        params.put("identifying_code", cardEvaluateSendSmsVo.getIdentifyingCode());
        params.put("serial_number", cardEvaluateSendSmsVo.getSerialNumber());
        params.put("user_id", cardEvaluateSendSmsVo.getUserId());
        JSONObject jsonObject = GuangGuUtil.request(params, "card_evaluate", "获取卡测评连接地址");
        return jsonObject;
    }


    /**
     * 获取办卡列表
     */
    public static JSONObject getApplyBankCardUrl(String companyId) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("company_id", companyId);
        JSONObject jsonObject = GuangGuUtil.request(params, "apply_bank_card", "获取办卡列表");
        return jsonObject;
    }

    /////////////////////碰一碰 S///////////////////////////////////////

    /**
     * 查询是否已经开通碰一碰
     */
    public static JSONObject pypQuerySgin(String companyId, String userId) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("company_id", companyId);
        params.put("user_id", userId);
        JSONObject jsonObject = GuangGuUtil.request(params, "pyp_query_sgin", "查询是否已经开通碰一碰");
        return jsonObject;
    }

    /**
     * 碰一碰商户进件
     */
    public static JSONObject openPyp(OpenPypVo openPypVo) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("company_id", openPypVo.getCompanyId());
        params.put("user_id", openPypVo.getUserId());
        //签约流水号
        params.put("seria_no", openPypVo.getSeriaNo());
        //银行卡号
        params.put("bank_card_no", openPypVo.getBankCardNo());
        //身份证正面
        params.put("img_id_card_z", openPypVo.getImgIdCardZ());
        //身份证反面
        params.put("img_id_card_f", openPypVo.getImgIdCardF());
        //银行卡正面照片
        params.put("img_bank_z", openPypVo.getImgBankZ());
        //手持身份证照片
        params.put("img_id_card_s", openPypVo.getImgIdCardS());
        //图片后缀
        params.put("img_suffix", openPypVo.getImgSuffix());
        JSONObject jsonObject = GuangGuUtil.request(params, "open_pyp", "碰一碰商户进件");
        return jsonObject;
    }

    /**
     * 碰一碰商户报备获取验证码
     */
    public static JSONObject pypSendSms(String companyId, String userId, String phone) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("company_id", companyId);
        params.put("user_id", userId);
        params.put("phone", phone);
        JSONObject jsonObject = GuangGuUtil.request(params, "pyp_send_sms", "碰一碰商户报备获取验证码");
        return jsonObject;
    }

    /**
     * 碰一碰商户报备
     */
    public static JSONObject pypReport(PypReportVo pypReportVo) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("company_id", pypReportVo.getCompanyId());
        params.put("user_id", pypReportVo.getUserId());
        params.put("sms_code", pypReportVo.getSmsCode());
        params.put("sms_id", pypReportVo.getSmsId());
        params.put("phone", pypReportVo.getPhone());
        return GuangGuUtil.request(params, "pyp_report", "碰一碰商户报备");
    }


    /**
     * 碰一碰查询省列表
     */
    public static JSONObject pypQueryProvince(String companyId, String userId) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("company_id", companyId);
        params.put("user_id", userId);
        return GuangGuUtil.request(params, "pyp_query_province", "碰一碰查询省列表");
    }

    /**
     * 碰一碰查询市列表
     */
    public static JSONObject pypQueryCity(String companyId, String userId, String provinceCode) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("company_id", companyId);
        params.put("user_id", userId);
        params.put("province_code", provinceCode);
        return GuangGuUtil.request(params, "pyp_query_city", "碰一碰查询市列表");
    }

    /**
     * 碰一碰查询县列表
     */
    public static JSONObject pypQueryCounty(String companyId, String userId, String cityCode) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("company_id", companyId);
        params.put("user_id", userId);
        params.put("city_code", cityCode);
        return GuangGuUtil.request(params, "pyp_query_city", "碰一碰查询县列表");
    }

    /**
     * 碰一碰查询大类别
     */
    public static JSONObject pypQueryMcc(String companyId, String userId) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("company_id", companyId);
        params.put("user_id", userId);
        return GuangGuUtil.request(params, "pyp_query_mcc", "碰一碰查询大类别");
    }

    /**
     * 碰一碰查询小类别
     */
    public static JSONObject pypQuerySubMcc(String companyId, String userId, String mccCode) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("company_id", companyId);
        params.put("user_id", userId);
        params.put("mcc_code", mccCode);
        return GuangGuUtil.request(params, "pyp_query_sub_mcc", "碰一碰查询小类别");
    }

    /**
     * 碰一碰新增商铺
     */
    public static JSONObject pypAddStore(PypAddStoreVo pypAddStoreVo) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("company_id", pypAddStoreVo.getCompanyId());
        params.put("user_id", pypAddStoreVo.getUserId());
        params.put("store_name", pypAddStoreVo.getStoreName());
        params.put("mcc_code", pypAddStoreVo.getMccCode());
        params.put("mcc_name", pypAddStoreVo.getMccName());
        params.put("sub_mcc_code", pypAddStoreVo.getSubMccCode());
        params.put("sub_mcc_name", pypAddStoreVo.getSubMccName());
        params.put("province_code", pypAddStoreVo.getProvinceCode());
        params.put("province_Name", pypAddStoreVo.getProvinceMame());
        params.put("city_code", pypAddStoreVo.getCityCode());
        params.put("city_name", pypAddStoreVo.getCityName());
        params.put("county_code", pypAddStoreVo.getCountyCode());
        params.put("county_name", pypAddStoreVo.getCountyName());
        params.put("notfiy_url", pypAddStoreVo.getNotfiyUrl());
        return GuangGuUtil.request(params, "pyp_add_store", "碰一碰新增商铺");
    }


    /**
     * 碰一碰商铺标签申请
     */
    public static JSONObject pypStoreEffect(String companyId, String userId, String uuid) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("company_id", companyId);
        params.put("user_id", userId);
        //贴纸uuid（app通过sdk获取卡片id）
        params.put("uuid", uuid);
        return GuangGuUtil.request(params, "pyp_store_effect", "碰一碰商铺标签申请");
    }

    /**
     * 碰一碰代付
     *
     * @throws Exception
     */
    public static JSONObject pypRePayment(Merchant merchant, String orderNo, String userId, BigDecimal orderAmount, BigDecimal pro) throws Exception {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        params.put("seria_no", orderNo);
        params.put("company_id", "3001");
        params.put("user_id", userId);
        params.put("trade_amount", orderAmount.toString());
        params.put("pro", pro.toString());
        params.put("notify_url", GuangGuConfig.PYP_REPAYMENT_URL);
        params.put("user_name", merchant.getMerchantCnName());
        params.put("bank_card_no", merchant.getBankAccount());
        params.put("user_id_card", merchant.getIdCardNumber());
        params.put("bank_card_phone", merchant.getReservePhone());
        params.put("bank_name", merchant.getBankName());
        params.put("bank_code", merchant.getBankCode());
        params.put("bank_channel_no", merchant.getBankDot());
        return GuangGuUtil.request(params, "pyp_rePayment", "碰一碰代付");
    }

    /////////////////////碰一碰 E///////////////////////////////////////

}
